package org.testfire.translator;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.testfire.model.*;
import org.testfire.model.assertions.*;
import org.testfire.model.commandtypes.ObjectCommandType;
import org.testfire.model.commandtypes.StringCommandType;
import org.testfire.model.commandtypes.VoidCommandType;
import org.testfire.translator.watij.*;
import org.testfire.translator.watij.assertions.*;
import org.testfire.translator.watij.commands.ObjectCommandToWatijTranslator;
import org.testfire.translator.watij.commands.StringCommandToWatijTranslator;
import org.testfire.translator.watij.commands.VoidCommandToWatijTranslator;

/**
 * Created by IntelliJ IDEA.
 * User: granum
 * Date: Sep 2, 2007
 * Time: 4:16:43 PM
 *
 */
public class TranslatorFactory<T extends TestFireTranslator>
{

    private TranslatorFactory(){}

    // key, class type
    public static final Map<String, String> usedVariableKeys = new HashMap<String, String>();

    private static final Map<Class, TestFireTranslator> noEdit = new HashMap<Class, TestFireTranslator>( );
    static{
        noEdit.put( VoidCommandType.class, new VoidCommandToWatijTranslator());
        noEdit.put( StringCommandType.class, new StringCommandToWatijTranslator());
        noEdit.put( ObjectCommandType.class, new ObjectCommandToWatijTranslator());
        noEdit.put( TasksType.class, new TasksToWatijTranslator());
        noEdit.put( ElementActionType.class, new ElementActionToWatijTranslator());
        noEdit.put( Engine.class, new EngineToWatijTranslator());
        noEdit.put( FinderType.class, new FinderToWatijTranslator());
        noEdit.put( HtmlFinderType.class, new HtmlFinderToWatijTranslator());
        noEdit.put( TestsetType.class, new TestsetToWatijTranslator());
        noEdit.put( TestType.class, new TestToWatijTranslator());
        noEdit.put( VersionType.class, new VersionToWatijTranslator());
        noEdit.put( VersionType.class, new VersionToWatijTranslator());


        noEdit.put( AssertionType.class, new AssertionTranslator());

	    noEdit.put( AssertDoubleEquals.class, new AssertDoubleEqualsTranslator());
        noEdit.put( AssertEquals.class, new AssertEqualsTranslator());
        noEdit.put( AssertFail.class, new AssertFailTranslator());
        noEdit.put( AssertNull.class, new AssertNullTranslator());
        noEdit.put( AssertSame.class, new AssertSameTranslator());
        noEdit.put( AssertTrueOrFalse.class, new AssertTrueOrFalseTranslator());

    }
    public static final Map<Class, ? extends TestFireTranslator> instances = Collections.unmodifiableMap(noEdit);

    public static TestFireTranslator get( Class key )
    {
        return instances.get( key );
    }

    public static Object translate( TestsetType testset, TestFireObject object )
    {
        return instances.get( object.getClass() ).translate( testset, object);
    }

    
}
